package com.biubiu.rotationchart;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.TransitionDrawable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class ViewPagerAdapter extends RecyclerView.Adapter<ViewPagerAdapter.ViewHolder> {
    private Context mContext;
    private List<String> mData;
    private LayoutInflater mInflater;
    private Map<Integer, View> pageMap = new HashMap<>();


    private int[] colorArray = new int[]{R.drawable.item01,R.drawable.item02,R.drawable.item03,R.drawable.item04};


    public ViewPagerAdapter(Context context, List<String> data) {
        this.mContext = context;
        this.mInflater = LayoutInflater.from(context);
        this.mData = data;
    }

    @NonNull
    @Override
    public ViewPagerAdapter.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = mInflater.inflate(R.layout.layout_image, parent, false);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull ViewPagerAdapter.ViewHolder holder, int position) {
        final int index = position % mData.size();
        String animal = mData.get(index);
        holder.imageView.setBackgroundResource(colorArray[index]);

        Drawable[] layers = new Drawable[2];
        TransitionDrawable transitionDrawable;

        pageMap.put(index, holder.imageView);
    }

    @Override
    public int getItemCount() {
        return Short.MAX_VALUE;
    }

    public View getPrimaryItem(int position) {
        int index = position % mData.size();
        return pageMap.get(index);
    }

    public class ViewHolder extends RecyclerView.ViewHolder {

        ImageView imageView;
        ViewHolder(View itemView) {
            super(itemView);
            imageView = itemView.findViewById(R.id.image_view);
        }
    }
}


